package main

import (
	"fmt"
	"ginswagger/controller"
	"ginswagger/pkg/setting"
	grouter "ginswagger/router"
	"github.com/gin-gonic/gin"
	"net/http"
)

func main()  {

	fmt.Print("hello world")
	router := gin.Default()

	//router.con
	router.GET("/test", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"message": "test",
		})
	})
	//设置后台管理页面
	//把公用的前缀提取出来，创建一个路由组
	bookGroup := router.Group("/book")
	{
		bookGroup.GET("/index", func(c *gin.Context) {
			//c.JSON(http.StatusOK, gin.H{"msg":"/video/index"})
			c.HTML(http.StatusOK,"login.html",controller.LoginGet)
		})

		bookGroup.GET("/video", func(c *gin.Context) {
			c.JSON(http.StatusOK, gin.H{"msg":"/video/xx"})
		})
		bookGroup.GET("/booklist", func(c *gin.Context) {
			c.JSON(http.StatusOK, gin.H{"msg":"/video/oo"})
		})
		bookGroup.GET("/bookdetail", func(c *gin.Context) {
			c.JSON(http.StatusOK, gin.H{"msg":"/video/oo"})
		})
		bookGroup.GET("/userlist", func(c *gin.Context) {
			c.JSON(http.StatusOK, gin.H{"msg":"/video/oo"})
		})
	}
	//grouter.InitBaseRoute();
	//设置api 访问路径
	apiGroup := router.Group("/bookapi")
	{
		apiGroup.GET("/index", func(c *gin.Context) {
			c.JSON(http.StatusOK, gin.H{
				"message": "bookapiIndex",
			})
		})

	}



	s := &http.Server{
		Addr:           fmt.Sprintf(":%d", setting.HTTPPort),
		Handler:        router,
		ReadTimeout:    setting.ReadTimeout,
		WriteTimeout:   setting.WriteTimeout,
		MaxHeaderBytes: 1 << 20,
	}

	grouter.SetupRouter()
	//rengin.Run()
	s.ListenAndServe()
}
